﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

public partial class Web_Distributor_Sales_Report : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Session["current"] = "Sales Report";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }
        if (IsPostBack==true)//check selected radio button
        {
            Session["button"] = "0";
            string button = Session["button"].ToString();
            if (button == "1")
            {
                button1();
                button1();
            }
            else
                if (button == "2")
                {
                    button2();
                    button2();
                }
                else
                    if (button == "3")
                    {
                        button3();
                        button3();
                    }
                    else
                        if (button == "4")
                        {
                            button4();
                            button4();
                        }
           
        }



        Label5.Visible = false;
        Label6.Visible = false;
        ASPxDateEdit1.Visible = false;
        ASPxDateEdit2.Visible = false;
        DropDownList1.Visible = false;
        DropDownList2.Visible = false;
        DropDownList5.Visible = false;
       
        Label2.Visible = false;
        Label3.Visible = false;
        Label4.Visible = false;
    }

    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        if (ASPxRadioButton1.Checked)
        {
            button1();
        }
        else if (ASPxRadioButton2.Checked)
        {
            button2();
        }
        else if (ASPxRadioButton3.Checked)
        {
            button3();
        }
        else if (ASPxRadioButton4.Checked)
        {
            button4();
        }
    
    }//find which radio button

    #region select which detail to show for  radio button
    protected void ASPxRadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton1.Checked)
        {
            ASPxDateEdit1.Visible = true;
            ASPxDateEdit2.Visible = true;
            Label5.Visible = true;
            Label6.Visible = true;

        }
    }

    protected void ASPxRadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton2.Checked)
        {
            Label2.Visible = true;
            DropDownList1.Visible = true;
        }
    }

    protected void ASPxRadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton3.Checked)
        {
            Label3.Visible = true;
            DropDownList2.Visible = true;
        }
    }

    protected void ASPxRadioButton4_CheckedChanged(object sender, EventArgs e)
    {
        if (ASPxRadioButton4.Checked)
        {
            Label4.Visible = true;
            DropDownList5.Visible = true;
        }

    }
    #endregion

    #region radio button actions
    public Boolean button1()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbydate.rpt"));
        reportdocument.SetDatabaseLogon("sa", "MahinBL2012@");
        reportdocument.SetParameterValue("From", ASPxDateEdit1.Text);
        reportdocument.SetParameterValue("To", ASPxDateEdit2.Text);
        reportdocument.SetParameterValue("status", DropDownList4.Text);
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] ="1";
        return true;
    }

    public Boolean button2()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbyinvoice.rpt"));
        reportdocument.SetDatabaseLogon("sa", "MahinBL2012@");
        reportdocument.SetParameterValue("idinvoice", DropDownList1.SelectedValue);
        reportdocument.SetParameterValue("status", DropDownList4.Text);
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] ="2";
        return true;
    }

    public Boolean button3()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbyproduct.rpt"));
        reportdocument.SetDatabaseLogon("sa", "MahinBL2012@");
        reportdocument.SetParameterValue("pro", DropDownList2.SelectedValue);
        reportdocument.SetParameterValue("status", DropDownList4.Text);
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] ="3";
        return true;
    }

    public Boolean button4()
    {
        ReportDocument reportdocument = new ReportDocument();
        reportdocument.Load(Server.MapPath("Bin/SalesReportbydistributor.rpt"));
        reportdocument.SetDatabaseLogon("sa", "MahinBL2012@");
        reportdocument.SetParameterValue("distributor", DropDownList5.Text);
        reportdocument.SetParameterValue("status", DropDownList4.Text);
        CrystalReportViewer1.ReportSource = reportdocument;
        CrystalReportViewer1.ParameterFieldInfo.Clear();
        Session["button"] ="4";
        return true;
    }
    #endregion
}